﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using DAL;

namespace BLL
{
    public class BTaxi
    {

        private readonly DAL.DTaxi _dTaxi = new DTaxi();
        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return _dTaxi.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string taxiNo)
        {
            return _dTaxi.Exists(taxiNo);
        }

        public List<string> GetCompanyList()
        {
            return _dTaxi.GetCompanyList();
        }

        public Model.ServerConfigInfo GetServerConfigByTaxiId(int id)
        {
            return _dTaxi.GetServerConfigByTaxiId(id);
        }

        public bool UpdateServerIdByTaxiId(int taxiId, int serverId)
        {
            return _dTaxi.UpdateServerIdByTaxiId(taxiId, serverId);
        }

        public string[] GetParametersByPhoneNum(string phoneNumber)
        {
            return _dTaxi.GetParametersByPhoneNum(phoneNumber);
        }


        public bool Add(Model.TaxiInfo model)
        {
            return _dTaxi.Add(model);
        }

        public bool Update(Model.TaxiInfo model)
        {
            return _dTaxi.Update(model);
        }

        public bool Delete(int id)
        {
            return _dTaxi.Delete(id);
        }

        public bool DeleteList(string idlist)
        {
            return _dTaxi.DeleteList(idlist);
        }

        public DataSet GetList(string strWhere)
        {
            return _dTaxi.GetList(strWhere);
        }

        public DataSet GetList(string parameter, string parameterVaule)
        {
            return _dTaxi.GetList(parameter, parameterVaule);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.TaxiInfo GetModel(int id)
        {

            return _dTaxi.GetModel(id);
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.TaxiInfo> GetModelList(string strWhere)
        {
            DataSet ds = _dTaxi.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.TaxiInfo> DataTableToList(DataTable dt)
        {
            List<Model.TaxiInfo> modelList = new List<Model.TaxiInfo>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.TaxiInfo model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.TaxiInfo();
                    if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
                    {
                        model.Id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    if (dt.Rows[n]["TaxiNo"] != null && dt.Rows[n]["TaxiNo"].ToString() != "")
                    {
                        model.TaxiNo = dt.Rows[n]["TaxiNo"].ToString();
                    }
                    if (dt.Rows[n]["TaxiType"] != null && dt.Rows[n]["TaxiType"].ToString() != "")
                    {
                        model.TaxiType = dt.Rows[n]["TaxiType"].ToString();
                    }
                    if (dt.Rows[n]["Remark"] != null && dt.Rows[n]["Remark"].ToString() != "")
                    {
                        model.Remark = dt.Rows[n]["Remark"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return _dTaxi.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return _dTaxi.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

      
    }
}
